const SingleTon = (function () {
  class Person {
    constructor() {
      this.ele = document.createElement("div")
      this.ele.classList.add("popup")
      document.body.appendChild(this.ele)
      this.bindEvent()
      this.callback = undefined
    }
    setInner(text) {
      this.ele.innerHTML = `
      <div class="middle">! &emsp;${text}</div>
      `
      this.ele.style.display = "flex"
    }
    bindEvent() {
      document.addEventListener("click", e => {
        if (e.target.className === "iconfont") {
          this.ele.style.display = "none"
        }
        if (e.target.className === "true") {
          this.ele.style.display = "none"
          this.callback(true)
        }
        if (e.target.className === "false") {
          this.ele.style.display = "none"
          this.callback(false)
        }
      })
    }
  }
  let instance = null
  return function setSingleTon(val, cb) {
    if (!instance) instance = new Person()
    instance.setInner(val)
    instance.callback = cb || function () { }
    return instance
  }
})()
